package cn.buk.tms.eotms.controller;

import cn.buk.common.dto.CommonDto;
import cn.buk.tms.eotms.dto.TrainRefundOrderDto;
import cn.buk.tms.eotms.sc.TrainOrderSearchCriteria;
import cn.buk.tms.eotms.service.TrainOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yfdai
 */
@RestController
@RequestMapping("/train/refund")
public class TrainRefundOrderController extends BaseController {

  @Autowired
  private TrainOrderService trainOrderService;

  @RequestMapping("/orders")
  public CommonDto<TrainRefundOrderDto> searchOrders(HttpServletRequest request,
                                                     @ModelAttribute("sc") TrainOrderSearchCriteria sc) {
    List<TrainRefundOrderDto> datas = trainOrderService.searchTrainRefundOrders(getUserId(request), sc);

    CommonDto<TrainRefundOrderDto> commonDto = new CommonDto<>();
    commonDto.setDataList(datas);
    commonDto.setPage(sc.getPage());

    return commonDto;
  }

  /**
   * 获取火车票退票订单详情
   * @param request
   * @return
   */
  @RequestMapping("/order/{orderId}")
  public TrainRefundOrderDto searchOrder(HttpServletRequest request,
                                         @PathVariable("orderId") final int orderId) {
    return trainOrderService.getTrainRefundOrderById(getUserId(request), orderId);
  }
}
